<template>
  <div class="image-viewer__wrapper" v-if="show">
    <div class="image-viewer__mask"></div>
    <div class="image-viewer__canvas">
      <div class="image-viewer__btn image-viewer__close" @click="close">
        <i class="el-icon-close" />
      </div>
      <div class="image-viewer__btn image-viewer__prev" @click="prev">
        <i class="el-icon-arrow-left" />
      </div>
      <div class="image-viewer__btn image-viewer__next" @click="next">
        <i class="el-icon-arrow-right" />
      </div>
      <el-image class="image-view" :src="getImgUrl">
        <div slot="error" class="image-slot" style="text-align: center">
          <i
            class="el-icon-picture-outline"
            style="font-size: 40px; margin-bottom: 20px"
          ></i>
          <div>未查询到核酸码信息</div>
        </div>
      </el-image>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      src: 'fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
      show: false
    }
  },
  props: {
    nucleicUrl: {
      type: String,
      default: ''
    }
  },
  computed: {
    getImgUrl () {
      return this.nucleicUrl ? `/gateway/api/basic/minio/getFileSource?fileName=${this.nucleicUrl}` : ''
    }
  },
  methods: {
    showPicturePreview () {
      this.show = true
    },
    prev () {
      this.$emit('prev')
    },
    next () {
      this.$emit('next')
    },
    close () {
      this.show = false
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>
.image-viewer__wrapper {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2040;
  display: flex;
  justify-content: center;
  align-items: center;
  .image-viewer__mask {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0.5;
    background: #000;
  }
  .image-viewer__canvas {
    position: relative;
    width: 500px;
    height: 700px;
    // margin: auto;
    .image-viewer__btn {
      position: absolute;
      z-index: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      opacity: 0.8;
      cursor: pointer;
      box-sizing: border-box;
      user-select: none;
    }
    .image-viewer__close {
      top: -20px;
      right: -20px;
      width: 40px;
      height: 40px;
      font-size: 24px;
      color: #fff;
      background-color: #606266;
    }
    .image-viewer__prev {
      top: 50%;
      transform: translateY(-50%);
      width: 44px;
      height: 44px;
      font-size: 24px;
      color: #fff;
      background-color: #606266;
      border-color: #fff;
      left: -100px;
    }
    .image-viewer__next {
      top: 50%;
      transform: translateY(-50%);
      width: 44px;
      height: 44px;
      font-size: 24px;
      color: #fff;
      background-color: #606266;
      border-color: #fff;
      right: -100px;
      text-indent: 2px;
    }
    .image-slot {
      text-align: center;
    }
    .image-view {
      // width: 500px;
      max-height: calc(100vh - 180px);
      background: #fff;
      border-radius: 5px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>
